Resize
对输入图像使用给定的插值方式去调整为给定的尺寸大小。
- 输入:
input - 输入数据的地址
param - 算子计算所需参数的结构体。其各成员见下述。
core_mask - 核掩码。
ResizeParameter定义:
1typedef struct ResizeParameter {
2 int* input_shape_; // 输入张量形状
3 int* output_shape_; // 输出张量形状
4 int* x_lefts_; // 用于存储预处理结果
5 int* x_rights_; // 用于存储预处理结果
6 int* y_tops_; // 用于存储预处理结果
7 int* y_bottoms_; // 用于存储预处理结果
8 void* x_weights_; // 用于存储预处理结果
9 void* y_weights_; // 用于存储预处理结果
10 void* line_buffers_; // 用于存储中间结果
11 int method_; // 所用的插值方法,0:最邻近插值,1:双线性插值,2:双三次插值
12 int coordinate_transform_mode_; // 像素点对齐方式,0:非对称,1:中心对齐,2:偏移半像素
13 float cubic_coeff_; // 一个仅在双三次插值中使用到的系数
14} ResizeParameter;
- 输出:
output - 输出地址。
- 支持平台:
FT78NEMT7004
备注
FT78NE 支持int8, fp32
MT7004 支持fp16, fp32
共享/私有存储版本:
-
void i8_resize_anycore(int8_t *input, int8_t *output, ResizeParameter *param, int core_mask)
-
void hp_resize_anycore(half *input, half *output, ResizeParameter *param, int core_mask)
-
void fp_resize_anycore(float *input, float *output, ResizeParameter *param, int core_mask)
私有及共享空间版本均使用这些函数。
C调用示例:
1void TestResizeFp32SMC(int* input_shape, int* output_shape, ResizeMethod method, CoordinateTransformMode mode, float cubic_coeff, int core_mask) {
2 int core_id = get_core_id();
3 int core_num = GetCoreNum(core_mask);
4 int logic_core_id = GetLogicCoreId(core_mask, core_id);
5 float* input = (float*)0x84000000; // 测试私有空间时地址设置在私有空间内即可
6 float* output = (float*)0x85000000;
7 ResizeParameter* param = (ResizeParameter*)0x86000000;
8 if (logic_core_id == 0) {
9 param->coordinate_transform_mode_ = mode;
10 param->method_ = method;
11 param->cubic_coeff_ = cubic_coeff;
12 param->input_shape_ = (int*)0x87000000;
13 memcpy(param->input_shape_, input_shape, sizeof(int) * 4);
14 param->output_shape_ = (int*)0x87100000;
15 memcpy(param->output_shape_, output_shape, sizeof(int) * 4);
16 param->line_buffers_ = (void*)0x88000000;
17 param->x_lefts_ = (int*)0x89000000;
18 param->x_rights_ = (int*)0x8A000000;
19 param->y_bottoms_ = (int*)0x8B000000;
20 param->y_tops_ = (int*)0x8C000000;
21 param->x_weights_ = (void*)0x8D000000;
22 param->y_weights_ = (void*)0x8E000000;
23 if (method == BILINEAR) {
24 PrepareResizeBilinear(param); // 做预处理
25 } else if (method == CUBIC) {
26 PrepareResizeBicubic(param, cubic_coeff); // 做预处理
27 }
28 }
29 sys_bar(0, core_num); // 初始化参数完成后进行同步
30 fp_resize_anycore(input, check, param, core_mask);
31}
32
33void main(){
34 int input_shape[4] = {2, 4, 4, 4};
35 int output_shape[4] = {2, 8, 8, 4};
36 ResizeMethod method = NEAREST;
37 CoordinateTransformMode mode = ALIGN_CORNERS;
38 float cubic_coeff = -0.75;
39 int core_mask = 0b1111; // 测试单核时核掩码设置为0b0001即可
40 TestResizeFp32SMC(input_shape, output_shape, method, mode, cubic_coeff, core_mask);
41}